home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / SetPriority.c < prev    next >
Text File  |  1995-07-03  |  3KB  |  84 lines

  1. /*
  2. SetPriority.c
  3.  
  4. char priority=7;
  5.  
  6. SwapPriority(&priority);
  7. // do high priority stuff here
  8. SwapPriority(&priority);
  9.  
  10. Get and set the processor priority. (This is modeled after SwapMMUMode.) The
  11. Macintosh operating system normally leaves the processor priority at zero,
  12. allowing all interrupts. You can temporarily block interrupts by raising the
  13. processor priority. The highest level is 7, blocking all interrupts. This is
  14. useful for time critical tasks, such as running video animations, where your
  15. primary concern is video timing, and you're willing to miss AppleTalk and
  16. keyboard events. Note that while the processor priority is high the keyboard and
  17. mouse will be dead, so that it is essential that your program lower it back down
  18. to allow the user to regain control.
  19.  
  20. The inline functions GetStatusRegister() and SetStatusRegister() only work
  21. because the processor is in supervisor state. As of this writing the Macintosh
  22. operating system (up to 7.0) always leaves the 680x0 processor in supervisor
  23. state. However, Apple has warned that this may change in future releases of the
  24. operating system. In the future, therefore, it may be necessary to write more
  25. elaborate versions of these two routines, begging the operating system's
  26. permission to do this, since it cannot be done while the processor is in user
  27. state.
  28.  
  29. HISTORY:
  30. 1989?    dgp    wrote it
  31. 8/1/91    dgp    introduced the inline functions as a way to isolate the machine code
  32.             part, and to make it compatible with MPW C as well as THINK C.
  33. 8/6/91    dgp    fixed definition of GetStatusRegister() to make it a legal prototype.
  34. 2/15/93    dgp    added SwapPriority().
  35. 7/29/94 dgp disable all code if compiling for PowerPC
  36. */
  37. #include "VideoToolbox.h"
  38.  
  39. /* These are 68k inline functions supported by THINK, MPW, and CodeWarrior C. */
  40. #if GENERATING68K
  41.     pascal short GetStatusRegister(void)=0x40d7;            /* MOVE.W SR,(SP)    */
  42.     pascal void SetStatusRegister(short status)=0x46df;        /* MOVE.W (SP)+,SR    */
  43. #endif
  44.  
  45. void SetPriority(int i)
  46. {
  47.     #if GENERATING68K
  48.         register short status;
  49.     
  50.         i &= 7;
  51.         i <<= 8;
  52.         status=GetStatusRegister();
  53.         status &= ~0x700;    /* clear the priority bits */
  54.         status |= i;        /* insert new priority bits */
  55.         SetStatusRegister(status);
  56.     #else
  57.         i;    // prevent "unused argument" warning
  58.     #endif
  59. }
  60.  
  61. int GetPriority(void)
  62. {
  63.     register short status=0;
  64.  
  65.     #if GENERATING68K
  66.         status=GetStatusRegister();
  67.         status >>= 8;
  68.         status &= 7;
  69.     #endif
  70.     return status;
  71. }
  72.  
  73. void SwapPriority(char *priority)
  74. {
  75.     #if GENERATING68K
  76.         char oldPriority;
  77.         
  78.         oldPriority=GetPriority();
  79.         SetPriority(*priority);
  80.         *priority=oldPriority;
  81.     #else
  82.         priority;    // prevent "unused argument" warning
  83.     #endif
  84. }